<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>驾驶员信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body class="layui-layout-body">
<blockquote class="layui-elem-quote"  >
                <div class=" layui-form" >
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <select name="searchKind"  lay-filter="searchKind" lay-search id="searchKind">
                                <option value="">请选搜索类型</option>
                                <option value="jsyxm">驾驶员姓名</option>
                                <option value="sfzh">身份证号</option>
                                <option value="jsysj">驾驶员手机</option>
                                <option value="zzzt">在职状态</option>
                                <option value="bumenid">所属部门</option>
                            </select>
                        </div>


                        <div class="layui-input-inline">
                            <div class="layui-input-inline"  >
                                <select    lay-filter="searchContentSelect" lay-search id="searchContentSelect">
                                </select>
                            </div>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-normal" id="search">点击搜索</button>
                            <button class="layui-btn layui-btn-normal" id="all"   >显示全部</button>
                        </div>



                        <div class="layui-input-inline" style="position: absolute;right: 0%;width: 10%">
                            <button id="new" class="layui-btn layui-btn-normal" >新增驾驶员信息</button>
                        </div>



                        <div class="layui-btn layui-btn-warm"  style="position: absolute;right: 30%;width: 100px">30天内过期</div>
                        <div class="layui-btn layui-btn-danger"  style="position: absolute;right: 23%;width: 100px">已经过期</div>

                    </div>
                </div>

</blockquote>
        <div class="layui-row">
            <div class="layui-col-xs12">
                <script type="text/html" id="opera">
                    {{#  if( getQueryVariable("D") == "false" && getQueryVariable("R") == "true"){ }}
                    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
                    <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="delete">删除</button>
                    {{# }else if(getQueryVariable("R") == "false"){ }}
                    <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="detail">查看</button>
                    <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="delete">删除</button>
                    {{# }else  { }}
                    <button class="layui-btn layui-btn-normal layui-btn-xs  "   lay-event="detail">查看</button>
                    <button class="layui-btn layui-btn-danger layui-btn-xs  "   lay-event="delete">删除</button>
                    {{# } }}

                </script>
                <table id="table" lay-filter="Table" ></table>
                <script id="jszyxqz" type="text/html">
                    {{#  if(dateToToday(d.jszyxqz) == '0'){ }}
                    <div style="background: orangered;">{{ d.jszyxqz }}</div>
                    {{#  } else if(dateToToday(d.jszyxqz) == '2')  { }}
                    <div style="background: #ffb803;">{{ d.jszyxqz }}</div>
                    {{#  } else if(dateToToday(d.jszyxqz) == '4')  { }}
                    <div  >{{ "" }}</div>
                    {{# }else { }}
                    <div style="">{{ d.jszyxqz }}</div>
                    {{#  } }}
                </script>

                <script id="cyzgzyxqz" type="text/html">
                    {{#  if(dateToToday(d.cyzgzyxqz) == '0'){ }}
                    <div style="background: orangered;">{{ d.cyzgzyxqz }}</div>
                    {{#  } else if(dateToToday(d.cyzgzyxqz) == '2')  { }}
                    <div style="background: #ffb803;">{{ d.cyzgzyxqz }}</div>
                    {{#  } else if(dateToToday(d.cyzgzyxqz) == '4')  { }}
                    <div  >{{ "" }}</div>
                    {{# }else { }}
                    <div style="">{{ d.cyzgzyxqz }}</div>
                    {{#  } }}
                </script>
            </div>
        </div>

<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['form' ,'table','element'], function(){
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.$;
        var tableheight= 'full-200';
        var tablewidth = 75;
        var currentPage = 1;
        //获取url参数 渲染 权限控制的页面
        if(getQueryVariable("C") == "false"){
            $("#new").attr("disabled",true) ;
            $("#new").addClass("layui-btn-disabled");
        }
        // 搜索
        form.on('select(searchKind)',function (data) {
            console.log(data);
            switch (data.value){
                case "jsyxm":
                    $("#searchContentSelect").empty();
                    $.ajax({
                        url: contextPath+"/driverlist",
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            $("#searchContentSelect").append("<option value=''>请选择</option>");
                            for(var i in res.list){
                                var option = "<option value='"+ res.list[i].jsyxm+ "'>"+res.list[i].jsyxm+"</option>";
                                $("#searchContentSelect").append(option);
                            };
                            form.render('select');
                        }
                    });
                    break;
                case "sfzh":
                    $("#searchContentSelect").empty();
                    $.ajax({
                        url: contextPath+"/driverlist",
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            $("#searchContentSelect").append("<option value=''>请选择</option>");
                            for(var i in res.list){
                                var option = "<option value='"+ res.list[i].sfzh+ "'>"+res.list[i].sfzh+"</option>";
                                $("#searchContentSelect").append(option);
                            };
                            form.render('select');
                        }
                    });
                    break;
                case "jsysj":
                    $("#searchContentSelect").empty();
                    $.ajax({
                        url: contextPath+"/driverlist",
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            $("#searchContentSelect").append("<option value=''>请选择</option>");
                            for(var i in res.list){
                                var option = "<option value='"+ res.list[i].jsysj+ "'>"+res.list[i].jsysj+"</option>";
                                $("#searchContentSelect").append(option);
                            };
                            form.render('select');
                        }
                    });
                    break;
                case "zzzt":
                    $("#searchContentSelect").empty();

                    var option1 = "<option value='在职'>在职</option>";
                    var option2 = "<option value='离职'>离职</option>";
                    $("#searchContentSelect").append("<option value=''>请选择</option>");
                    $("#searchContentSelect").append(option1);
                    $("#searchContentSelect").append(option2);
                    form.render('select');
                    break;
                case "bumenid":
                    $("#searchContentSelect").empty();
                    $.ajax({
                        url: contextPath+"/deptlist",
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            $("#searchContentSelect").append("<option value=''>请选择</option>");
                            for(var i in res.list){

                                var option = "<option value='"+ res.list[i].bumenid+ "'>"+res.list[i].name+"</option>";
                                $("#searchContentSelect").append(option);
                            };
                            form.render('select');
                        }
                    });
                    break;
                default:
                    break;
            }
        });

        $("#all").on('click',function () {
            url = contextPath+"/driver";
            var index = layer.load(1, {time: 10*1000});
            $.ajax({
                url: url,
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {
                    layer.close(index)
                    table.render({
                        elem: '#table'
                        ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                        ,data:res.list
                        ,page: {
                                    curr: 1 //重新从第 1 页开始
                            ,layout:['prev', 'page', 'next','skip','count']
                                } //开启分页
                        ,limit:10
                        ,cellMinWidth: tablewidth
                        ,cols: [[ //表头
                            { type:'numbers', title: '序号',  align:'center'  }
                            ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                            ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                            ,{field: 'sfzh', title: '身份证号',    align:'center'}
                            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}

                            ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                            ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}
                        ]]
                    });
                }

            });

        });
        var url = contextPath+"/driver?"+"type="+$("#searchKind").val()+"&"+'value='+$("#searchContentSelect").val();

        $("#search").on('click',function () {
            url = contextPath+"/driver?"+"type="+$("#searchKind").val()+"&"+'value='+$("#searchContentSelect").val();
            console.log(url);
            $.ajax({
                url: url,
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {

                    table.render({
                        elem: '#table'
                        ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                        ,data:res.list
                        ,page: {
                                    curr: 1 //重新从第 1 页开始
                            ,layout:['prev', 'page', 'next','skip','count']
                                } //开启分页
                        ,limit:10
                        ,cellMinWidth: tablewidth
                        ,cols: [[ //表头
                            { type:'numbers', title: '序号',  align:'center'  }
                            ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                            ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                            ,{field: 'sfzh', title: '身份证号',    align:'center'}
                            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}


                            ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                            ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}
                        ]]
                    });
                }

            });

        });

        $('#new').click(function () {
            layer.open({
                cancel: function(index, layero){
                    var faIndex = index;
                    layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title:'提示'}, function(index){
                        //do something
                        layer.close(index);
                        layer.close(faIndex);
                    });
                    return false
                },
                type: 2,
                title: '新增驾驶员信息',
                maxmin: true,
                shadeClose: false, //点击遮罩关闭层
                area : ['80%' , '80%'],
                content: './newDriver.html',
                end:function(){
                    $.ajax({
                        url: contextPath+"/driver",
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            table.render({
                                elem: '#table'
                                ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                                ,data:res.list
                                ,page: {
                                    curr: currentPage //重新从第 1 页开始
                                    ,layout:['prev', 'page', 'next','skip','count']
                                } //开启分页
                                ,limit:10
                                ,cellMinWidth: tablewidth
                                ,cols: [[ //表头
                                    { type:'numbers', title: '序号',  align:'center'  }
                                    ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                                    ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                                    ,{field: 'sfzh', title: '身份证号',    align:'center'}
                                    ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}


                                    ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                                    ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                                    ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}
                                ]]
                                ,done: function(res, curr, count){
                                    //得到当前页码
                                    console.log(curr);
                                    currentPage = curr;
                                }
                            });
                        }

                    });
                }
            });
        });
        //table实例
        var index = layer.load(1, {time: 10*1000});
        $.ajax({
            url: url,
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                layer.close(index);
                table.render({
                    elem: '#table'
                    ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                    ,data:res.list
                    ,page: {
                                    curr: currentPage //重新从第 1 页开始
                        ,layout:['prev', 'page', 'next','skip','count']
                                } //开启分页
                    ,limit:10
                    ,cellMinWidth: 1
                    ,cols: [[ //表头
                        { type:'numbers', title: '序号',  align:'center'  }
                        ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                        ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                        ,{field: 'sfzh', title: '身份证号',    align:'center'}
                        ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}


                        ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                        ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                        ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}

                    ]]
                    ,done: function(res, curr, count){
                        //得到当前页码
                        console.log(curr);
                        currentPage = curr;
                    }
                });
            }

        });


        //监听工具条
        table.on('tool(Table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
                layer.open({
                    cancel: function(index, layero){
                        var body = layer.getChildFrame('body',index);
                        var faIndex = index;
                        console.log(layero);
                        if(!(body.contents().find("#modiSub").hasClass("layui-btn-disabled"))){

                            layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title:'提示'}, function(index){
                                //do something
                                layer.close(index);
                                layer.close(faIndex);
                            });
                        }else {
                            layer.close(faIndex);
                        }

                        return false
                    },
                    type: 2,
                    title: '查看驾驶员信息',
                    maxmin: true,
                    shadeClose: false, //点击遮罩关闭层
                    area : ['80%' , '80%'],
                    content: './lookDriver.html',
                    success:function(layero,index){
                        console.log(data);
                        var body = layer.getChildFrame('body',index);
                        data.isU = getQueryVariable("U");
                        for(var i in data){
                            body.contents().find("[name='"+i+"']").val(eval("data."+i));
                        }
                    },
                    end:function(){
                        $.ajax({
                            url: url,
                            type: "GET",
                            contentType:"application/json;charset=utf-8",
                            dataType:"json",
                            success: function(res) {
                                table.render({
                                    elem: '#table'
                                    ,height:tableheight
                                    ,data:res.list
                                    ,page: {
                                    curr: currentPage //重新从第 1 页开始
                                        ,layout:['prev', 'page', 'next','skip','count']
                                } //开启分页
                                    ,limit:10
                                    ,cellMinWidth: tablewidth
                                    ,cols: [[ //表头
                                        { type:'numbers', title: '序号',  align:'center'  }
                                        ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                                        ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                                        ,{field: 'sfzh', title: '身份证号',    align:'center'}
                                        ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}


                                        ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                                        ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                                        ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}
                                    ]]
                                    ,done: function(res, curr, count){
                                        //得到当前页码
                                        console.log(curr);
                                        currentPage = curr;
                                    }
                                });
                            }

                        });
                    }
                });
            } else if(layEvent === 'delete'){
                layer.confirm('确定删除？', function(index){

                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        url: contextPath+"/driver/"+data.sjid,
                        type: "DELETE",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            if(res.message == "删除成功！"){
                                obj.del(); //删除对应行（tr）的DOM结构
                            }
                            layer.msg(res.message);
                            $.ajax({
                                url: url,
                                type: "GET",
                                contentType:"application/json;charset=utf-8",
                                dataType:"json",
                                success: function(res) {
                                    table.render({
                                        elem: '#table'
                                        ,height:tableheight
                                        ,data:res.list
                                        ,page: {
                                            curr: currentPage //重新从第 1 页开始
                                            ,layout:['prev', 'page', 'next','skip','count']
                                        } //开启分页
                                        ,limit:10
                                        ,cellMinWidth: tablewidth
                                        ,cols: [[ //表头
                                            { type:'numbers', title: '序号',  align:'center'  }
                                            ,{field: 'jsyxm', title: '驾驶员姓名' ,align:'center'}
                                            ,{field: 'zzzt', title: '在职状态' ,  align:'center'}
                                            ,{field: 'sfzh', title: '身份证号',    align:'center'}
                                            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}


                                            ,{templet: '#jszyxqz', title: '驾驶证有效期止' ,align:'center'}
                                            ,{templet: '#cyzgzyxqz', title: '从业证有效期止' ,align:'center'}
                                            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera'}
                                        ]]
                                        ,done: function(res, curr, count){
                                            //得到当前页码
                                            console.log(curr);
                                            currentPage = curr;
                                        }
                                    });
                                }

                            });
                        }
                    });
                });
            }
        });

        form.on('submit(newInfo)', function(data){
            console.log(JSON.stringify(data.field));
            $.ajax({
                url: contextPath+"/driver",
                type: "POST",
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify(data.field) ,
                dataType:"json",
                success: function(res) {

                    $(".layui-input").val("");
                    layer.msg(res.message);
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });





</script>
</body>
</html>